<?php
namespace Sys\Controller;
use Common\Controller\BaseController;
class CreditController extends BaseController{
	public function __construct(){
		parent::__construct();
	}

	public function index(){
		$this-> display();
	}

	public function credit(){
		if(I('post.points_time')){
			$tableTime = I('post.points_time');
		}else{
			$tableTime = date('Y-m-d');
		}
		//学生
		$studentW['term_id']	= I('post.term_id');
		if(I('post.sname')){
			$studentW['sname'] = ['like','%'.I('post.sname').'%'];
			$where['sname'] = ['like','%'.I('post.sname').'%'];
			$this-> assign('sname',I('post.sname'));
		}
		$where['term_id'] = I('post.term_id');
		$this-> assign('nowTerm',I('post.term_id'));
		$where['DATE_FORMAT(points_time,"%Y-%m-%d")']  = array('eq',$tableTime);
		$article = M('points_rule')-> field('points_rules_id,rule_name')-> select();
		$student = M('students')->where($studentW)-> field('sname,student_id')-> select();
		$pointJson = M('points')
					-> join('pj_students ON pj_students.student_id = pj_points.student_id')
					-> where($where)
					-> field('points_rules_id,pj_students.student_id,points_id,term_id')
					-> select();
		$termId = M('dict')-> where(['field'=>'term'])-> select();
		$pointJson = json_encode($pointJson);
		$this-> assign('term',$termId);
		$this-> assign('time',$tableTime);
		$this-> assign('pointJson',$pointJson);
		$this-> assign('student',$student);
		$this-> assign('article',$article);
		$this-> display();
	}
	public function deduct(){
		D('points')-> create();
		$id = D('points')-> add();
		$this-> ajaxReturn($id);
	}

	public function editCredit(){
		M('points')-> delete(I('post.id'));
	}
}